# -*- encoding:utf-8 -*-
# __author__ = 'chenyongbing'
# __poject__ = 'ops_platform'
# __datetime__ = '2022/5/12'
# __name__ = 'filters.py'
from django_filters.rest_framework import FilterSet
import django_filters

from .models import *
# Create your code here.

class RoleFilter(FilterSet):
    """
        支持模糊搜索
        icontains，包含且忽略大小写
        """
    name = django_filters.CharFilter(field_name='name', lookup_expr='icontains')
    code = django_filters.CharFilter(field_name='code', lookup_expr='icontains')

    class Meta:
        # 指定模型
        models = Role
        # 指定需要模糊查询的字段
        fields = ['name', 'code']

class UserFilter(FilterSet):
    """
        支持模糊搜索
        icontains，包含且忽略大小写
        """
    name = django_filters.CharFilter(field_name='name', lookup_expr='icontains')
    username = django_filters.CharFilter(field_name='username', lookup_expr='icontains')

    class Meta:
        # 指定模型
        models = User
        # 指定需要模糊查询的字段
        fields = ['name', 'username']